package layouts;

import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutCompat;
import android.util.Log;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import top.yunqisong.firstapp.R;

/**
 * Created by YunQisong on 2017/9/2.
 */

public class LinearLayoutActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LinearLayout linearLayout = new LinearLayout(LinearLayoutActivity.this);// 在当前页面创建一个线性布局
        // 三个构造参数 Height Width Wight
        LinearLayoutCompat.LayoutParams layoutParams =
                new LinearLayoutCompat.LayoutParams(LinearLayoutCompat.LayoutParams.MATCH_PARENT,
                        LinearLayoutCompat.LayoutParams.MATCH_PARENT, 1);
        linearLayout.setLayoutParams(layoutParams);
        linearLayout.setOrientation(LinearLayout.VERTICAL);

        for (int i = 0; i < 3; i++) {
            TextView view = new TextView(LinearLayoutActivity.this);

            Log.i("wight:", String.valueOf(i));
            view.setLayoutParams(
                    new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, i + 1));
            if (i == 1)
                view.setBackgroundColor(getResources().getColor(R.color.colorAccent));
            else if (i == 2)
                view.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
            else
                view.setBackgroundColor(getResources().getColor(R.color.colorPrimaryDark));
            view.setText("text-view_" + i);

            linearLayout.addView(view);
        }

        setContentView(linearLayout);
    }


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
    }
}
